package com.kpx.app.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.kpx.app.R;
import com.kpx.app.base.ActivityBase;
import com.kpx.app.bean.LoginUser;
import com.kpx.app.bean.Wallet;
import com.kpx.app.utils.UIUtils;
import com.kpx.app.utils.UserInfoUtils;
import com.kpx.app.utils.uiutils.IntentUtil;
import com.kpx.app.view.TitleView;

import java.text.DecimalFormat;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/4/3.
 * 我的钱包
 */

public class ActivityMyWallet extends ActivityBase {
    @BindView(R.id.titleview)
    TitleView titleview;
    @BindView(R.id.txt_total_price)
    TextView txtTotalPrice;
    @BindView(R.id.txt_canuse_price)
    TextView txtCanusePrice;
    @BindView(R.id.ll_canuse_detail)
    LinearLayout llCanuseDetail;
    @BindView(R.id.txt_dongjie_price)
    TextView txtDongjiePrice;
    @BindView(R.id.ll_dongjie_price)
    LinearLayout llDongjiePrice;
    @BindView(R.id.txt_points)
    TextView txtPoints;
    @BindView(R.id.ll_points)
    LinearLayout llPoints;
    @BindView(R.id.btn_tixian)
    Button btnTixian;
    @BindView(R.id.btn_pwd)
    Button btn_pwd;

    @Override
    public void initview(@Nullable Bundle savedInstanceState) {
        setContentView(R.layout.activity_my_wallet);
        ButterKnife.bind(this);
        UIUtils.setNormalTitle(titleview, "我的钱包");
        titleview.setRight("提现明细", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityWalletDetailList.inType = ActivityWalletDetailList.TYPE_DETAIL_WITH;
                IntentUtil.gotoActivity(ActivityMyWallet.this, ActivityWalletDetailList.class);
            }
        },R.color.white);
        titleview.setTxtSize(0,10);
    }
    DecimalFormat df = new DecimalFormat("###0.00");
    @Override
    public void initData() {
        if (UserInfoUtils.isUserLogin()) {
            LoginUser loginUser = UserInfoUtils.getCachedLoginUser();
            if (loginUser != null) {
                Wallet wallet = loginUser.getWALLET();
                if (wallet != null) {
                    txtCanusePrice.setText(df.format(wallet.getCashAmount()));//账号余额
                    txtDongjiePrice.setText(df.format(wallet.getBlockedAmount()));//今日收入
                    txtPoints.setText(df.format(wallet.getIntegralAmount()));//本月收入
                    txtTotalPrice.setText(df.format(wallet.getCashAmount()));//推广收入
                }
            }
        }
    }

    @Override
    public void onReceiver(Context context, Intent intent) {

    }

    @OnClick({R.id.ll_canuse_detail, R.id.ll_dongjie_price, R.id.ll_points, R.id.btn_tixian, R.id.btn_pwd})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ll_canuse_detail:
                ActivityWalletDetailList.inType = ActivityWalletDetailList.TYPE_DETAIL_CANUSE;
                IntentUtil.gotoActivity(this, ActivityWalletDetailList.class);
                break;
            case R.id.ll_dongjie_price:
                ActivityWalletDetailList.inType = ActivityWalletDetailList.TYPE_DETAIL_DONGJIE;
                IntentUtil.gotoActivity(this, ActivityWalletDetailList.class);
                break;
            case R.id.ll_points:
                ActivityWalletDetailList.inType = ActivityWalletDetailList.TYPE_DETAIL_POINT;
                IntentUtil.gotoActivity(this, ActivityWalletDetailList.class);
                break;
            case R.id.btn_tixian:
                IntentUtil.gotoActivity(this, ActivityWithdrawals.class);
                break;
            case R.id.btn_pwd:
                IntentUtil.gotoActivity(this, ActivityResetTxPwd.class);
                break;
        }
    }
}
